<?php

namespace app\radar\model;

use app\BaseModel;


class RadarCard extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_user_info';


    protected static function init ()
    {
        //TODO:初始化内容
    }

    /**
     * @Purpose: 名片信息
     *
     * @Author: zzf
     *
     * @Return: mixed 查询返回值（结果集对象）
     */
    public function cardInfo ( $userId, $field = ['a.*', 'b.name as job_name'] )
    {
        $data = self::alias( 'a' )
                    ->where( [ [ 'a.fans_id', '=', $userId ] ] )
                    ->join( 'longbing_card_job b', 'a.job_id = b.id' )
                    ->field( $field )
                    ->find()
                    ->toArray();
        $data = transImages( $data, [ 'avatar', 'bg', 'images', 'my_video', 'my_video_cover', 'vr_cover', 'vr_path' ]
        );

        if ( $data )
        {
            if (isset($data['job_name']) && !$data['job_name'])
            {
                $data['job_name'] = '未设置职位';
            }

            $modelRadar = new RadarCount();
            list ( $shareCount, $viewCount, $thumbCount ) = $modelRadar->RadarNumber( $userId );

            $data[ 'shareCount' ] = $shareCount;
            $data[ 'viewCount' ]  = $viewCount;
            $data[ 'thumbCount' ] = $thumbCount;
        }

        if ( $data && isset( $data[ 'my_video' ] ) && is_array( $data[ 'my_video' ] ) && !empty( $data[ 'my_video' ] ) )
        {
            $data[ 'my_video_vid' ] = lbGetTencentVideo( $data[ 'my_video' ][ 0 ] );
        }

        return $data;
    }

}